package com.zt.ztyh.admin.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zt.ztyh.model.common.Result;
import com.zt.ztyh.model.dto.UserDto;
import com.zt.ztyh.model.entity.User;
import com.zt.ztyh.admin.service.UserService;
import com.zt.ztyh.admin.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 贾天旺
* @description 针对表【ztyh_user】的数据库操作Service实现
* @createDate 2024-04-12 18:13:09
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
    implements UserService{

    @Autowired
    private UserMapper userMapper;

    @Override
    public Page<User> findAll(Integer page, Integer limit, UserDto userDto) {
        if(ObjectUtil.isNotEmpty(userDto.getUsername())){
            return this.userMapper.selectPage(new Page<User>(page,limit),new QueryWrapper<User>().like("username",userDto.getUsername()));
        }
        if(ObjectUtil.isNotEmpty(userDto.getCreateTimeBegin()) || ObjectUtil.isNotEmpty(userDto.getCreateTimeEnd())){
            return this.userMapper.selectPage(new Page<User>(page,limit),new QueryWrapper<User>().between("createTime",userDto.getCreateTimeBegin(),userDto.getCreateTimeEnd()));
        }
        return this.userMapper.selectPage(new Page<User>(page,limit),null);
    }
}




